package com.lfy.auth.controller;

import com.lfy.auth.domain.req.LoginReq;
import com.lfy.auth.domain.req.RegReq;
import com.lfy.auth.domain.resp.LoginResp;
import com.lfy.auth.service.UserService;
import com.lfy.common.result.R;
import com.lfy.commons.anno.limit.CurrentLimit;
import com.lfy.commons.anno.user.NoNeedLogin;
import com.lfy.commons.strategy.LimitStrategyEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    private UserService userService;

    /**
     * 注册
     */
    @CurrentLimit(time = 1,once = 10,nuit = TimeUnit.DAYS,strategy = LimitStrategyEnum.Ip)
    @PostMapping("/reg")
    @NoNeedLogin
     public R<Void> reg(@Valid @RequestBody RegReq regReq){
         return this.userService.reg(regReq);
     }



    /**
     * 登录
     * @return
     */
    @PostMapping("/login")
    @NoNeedLogin
    public R<LoginResp> login(@Valid @RequestBody LoginReq loginReq, HttpServletResponse response){
        return this.userService.login(loginReq,response);
    }


     @GetMapping("/test")
     @NoNeedLogin
     @CurrentLimit(time = 1,once = 10,nuit = TimeUnit.DAYS,strategy = LimitStrategyEnum.Ip)
     public R test( ){

         return R.success();
     }


}
